<!-- PromotionForm.vue -->

<template>
  <el-dialog :title="mode" :visible.sync="dialogVisible">
    <el-form :model="formData" ref="promotionForm" label-width="80px">
      <!-- Form fields go here -->
      <el-form-item label="活动名称">
        <el-input v-model="formData.name"></el-input>
      </el-form-item>
      <el-form-item label="开始日期">
        <el-date-picker
          v-model="formData.startDate"
          type="date"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期">
        <el-date-picker v-model="formData.endDate" type="date"></el-date-picker>
      </el-form-item>
      <el-form-item label="折扣">
        <el-input v-model="formData.discountPercent"></el-input>
      </el-form-item>
      <!-- Add other form fields -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close()">关闭</el-button>
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addActive, delActive } from "@/api/promotion";
import { Message } from "element-ui";
export default {
  props: {
    dialogTitle: String,
  },
  data() {
    return {
      dialogVisible: false,
      formData: {},
    };
  },
  computed:{
    mode() {
      return this.dialogTitle === "add" ? "添加活动" : "编辑活动";
    },
  },
  methods: {
    handleSubmit() {
      if (this.dialogTitle === "add") {
        this.add();
      } else {
        this.edite();
      }
    },
    async add() {
      const param = { ...this.formData };
      const res = await addActive(param);
      if (res.code == 200) {
        Message(res.message);
      } else {
        Message(res.message);
      }
    },
    async edite() {
      const param = { ...this.formData };
      const res = await delActive(param);
      if (res.code == 200) {
        Message(res.message);
      } else {
        Message(res.message);
      }
    },
    close() {
      this.dialogVisible = false;
    },
  },
};
</script>
